% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/acs_bybg.R
\name{acs_bybg}
\alias{acs_bybg}
\title{download ACS 5year data from Census API, at block group resolution (slowly for entire US)}
\usage{
acs_bybg(
  variables = c(pop = "B01001_001"),
  table = NULL,
  cache_table = FALSE,
  year = 2022,
  output = "wide",
  state = EJAM::stateinfo$ST,
  county = NULL,
  zcta = NULL,
  geometry = FALSE,
  keep_geo_vars = FALSE,
  summary_var = NULL,
  key = NULL,
  moe_level = 90,
  survey = "acs5",
  show_call = FALSE,
  geography = "block group",
  dropname = TRUE,
  ...
)
}
\arguments{
\item{variables}{Vector of variables - see get_acs from tidycensus package}

\item{table}{see get_acs from tidycensus package}

\item{cache_table}{see get_acs from tidycensus package}

\item{year}{e.g., 2022  see get_acs from tidycensus package}

\item{output}{see get_acs from tidycensus package}

\item{state}{Default is 2-character abbreviations, vector of all US States, DC, and PR.}

\item{county}{see get_acs from tidycensus package}

\item{zcta}{see get_acs from tidycensus package}

\item{geometry}{see get_acs from tidycensus package}

\item{keep_geo_vars}{see get_acs from tidycensus package}

\item{summary_var}{see get_acs from tidycensus package}

\item{key}{see get_acs from tidycensus package}

\item{moe_level}{see get_acs from tidycensus package}

\item{survey}{see get_acs from tidycensus package}

\item{show_call}{see get_acs from tidycensus package}

\item{geography}{"block group"}

\item{dropname}{whether to drop the column called NAME}

\item{...}{see get_acs from tidycensus package}
}
\value{
data.table (not tibble, and not just a data.frame)
}
\description{
download ACS 5year data from Census API, at block group resolution (slowly for entire US)
}
\examples{
## All states, full table
# newvars <- acs_bybg(table = "B01001")

## One state, some variables
newvars <- acs_bybg(c(pop = "B01001_001", y = "B01001_002"), state = "DC")

## Format new data to match rows of blockgroupstats

setnames(newvars, "GEOID", "bgfips")
dim(newvars)
newvars <- newvars[blockgroupstats[,.(bgfips, ST)], ,  on = "bgfips"]
dim(blockgroupstats)
dim(newvars)
newvars
newvars[ST == "DC", ]

## Calculate a new indicator for each block group, using ACS data

newvars <- acs_bybg(variables = c("B01001_001", paste0("B01001_0", 31:39)),
  state = "DC")
setnames(newvars, "GEOID", "bgfips")
newvars <- newvars[blockgroupstats[, .(bgfips, ST)], , on = "bgfips"]
names(newvars) <- gsub("E$", "", names(newvars))
formula1 <- c(
 "pop = B01001_001",
 "age1849female = (B01001_031 + B01001_032 + B01001_033 + B01001_034 + 
 B01001_035 + B01001_036 + B01001_037 + B01001_038 + B01001_039)", 
 "pct1849female = ifelse(pop == 0, 0, age1849female / pop)")
newvars <- calc_ejam(newvars, formulas = formula1, 
  keep.old = c("bgid", "ST", "pop"))
newvars[ST == "DC", ]

}
